package com.ruoyi.cms.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.cms.domain.SysCmsLink;
import com.ruoyi.cms.service.ISysCmsLinkService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 友情链接Controller
 * 
 * @author he
 * @date 2025-06-24
 */
@RestController
@RequestMapping("/cms/link")
public class SysCmsLinkController extends BaseController
{
    @Autowired
    private ISysCmsLinkService sysCmsLinkService;

    /**
     * 查询友情链接列表
     */
    @PreAuthorize("@ss.hasPermi('cms:link:list')")
    @GetMapping("/list")
    public TableDataInfo list(SysCmsLink sysCmsLink)
    {
        startPage();
        List<SysCmsLink> list = sysCmsLinkService.selectSysCmsLinkList(sysCmsLink);
        return getDataTable(list);
    }

    /**
     * 导出友情链接列表
     */
    @PreAuthorize("@ss.hasPermi('cms:link:export')")
    @Log(title = "友情链接", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, SysCmsLink sysCmsLink)
    {
        List<SysCmsLink> list = sysCmsLinkService.selectSysCmsLinkList(sysCmsLink);
        ExcelUtil<SysCmsLink> util = new ExcelUtil<SysCmsLink>(SysCmsLink.class);
        util.exportExcel(response, list, "友情链接数据");
    }

    /**
     * 获取友情链接详细信息
     */
    @PreAuthorize("@ss.hasPermi('cms:link:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(sysCmsLinkService.selectSysCmsLinkById(id));
    }

    /**
     * 新增友情链接
     */
    @PreAuthorize("@ss.hasPermi('cms:link:add')")
    @Log(title = "友情链接", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody SysCmsLink sysCmsLink)
    {
        return toAjax(sysCmsLinkService.insertSysCmsLink(sysCmsLink));
    }

    /**
     * 修改友情链接
     */
    @PreAuthorize("@ss.hasPermi('cms:link:edit')")
    @Log(title = "友情链接", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody SysCmsLink sysCmsLink)
    {
        return toAjax(sysCmsLinkService.updateSysCmsLink(sysCmsLink));
    }

    /**
     * 删除友情链接
     */
    @PreAuthorize("@ss.hasPermi('cms:link:remove')")
    @Log(title = "友情链接", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(sysCmsLinkService.deleteSysCmsLinkByIds(ids));
    }
}
